<template>
  <!-- 添加或修改入库信息管理对话框 -->
  <el-dialog :title="title" :visible.sync="open" width="60%" append-to-body :close-on-click-modal="false"
             v-dialogDrag>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-tabs v-model="activeName" class="detail-tab" type="card">
        <el-tab-pane label="基本信息" name="first">
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="电费成本" prop="shuidianFee">
                <el-input-number :precision="2" v-model="form.shuidianFee" placeholder="请输入电费成本"/>元
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="设备折旧费" prop="shebeiFee">
                <el-input-number :precision="2" v-model="form.shebeiFee" placeholder="请输入设备折旧费"/>元
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="磨具折旧费" prop="mojuFee">
                <el-input-number :precision="2" v-model="form.mojuFee" placeholder="请输入磨具折旧费"/>元
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="辅料费" prop="fuliaoFee">
                <el-input-number :precision="2" v-model="form.fuliaoFee" placeholder="请输入辅料费"/>元
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="24">
            <el-col :span="12">
              <el-form-item label="维保费" prop="weibaoFee">
                <el-input-number :precision="2" v-model="form.weibaoFee" placeholder="请输入维保费"/>元
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="废料费" prop="feiliaoFee">
                <el-input-number :precision="2" v-model="form.feiliaoFee" placeholder="请输入废料费"/>元
              </el-form-item>
            </el-col>
            <!--<el-col :span="12">
              <el-form-item label="管理费" prop="costPrice">
                <el-input-number :precision="2" v-model="form.costPrice" placeholder="请输入管理费"/>
              </el-form-item>
            </el-col>-->

          </el-row>
        </el-tab-pane>
      </el-tabs>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm" v-if="showBtn">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import {addAction, getById, updateAction} from '@/api/manage';

  export default {
    name: "FeeOrderinForm",
    data() {
      return {
        // 遮罩层
        loading: true,
        activeName: "first",
        // 弹出层标题
        title: "费用明细",
        // 是否显示弹出层
        open: false,
        // 表单参数
        form: {
          feeStatus: "1",
        },
        // 表单校验
        rules: {
        },
        url: {
          getById: '/goodsOrderIn/goodsOrderIn/',
          add: '/goodsOrderIn/goodsOrderIn/add',
          edit: '/goodsOrderIn/goodsOrderIn/editFee',
        },
        minus: 0,
        showBtn: true,
      };
    },
    created() {

    },
    methods: {
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          shuidianFee: null,
          shebeiFee: null,
          mojuFee: null,
          fuliaoFee: null,
          weibaoFee: null,
          feiliaoFee: null,
          yewuFee: null,
          userFee: null,
          feeStatus: "1",
          remark: null,
        };
        this.resetForm("form");
      },
      /** 修改按钮操作 */
      show(row) {
        this.reset();
        this.form = row;
        this.open = true;
      },
      /** 提交按钮 */
      submitForm() {
        let that = this;
        that.$refs["form"].validate(valid => {
          if (valid) {
            if (that.form.id != null) {
              this.form.feeStatus="1";
              updateAction(that.url.edit, that.form).then(response => {
                that.$modal.msgSuccess("修改成功");
                that.open = false;
                that.$emit('ok');
              });
            } else {
              addAction(that.url.add, that.form).then(response => {
                that.$modal.msgSuccess("新增成功");
                that.open = false;
                that.$emit('ok');
              });
            }
          }
        });
      },
    }
  };
</script>
